package com.pan.hisystem.controller;

import com.pan.hisystem.pojo.RespBean;
import com.pan.hisystem.pojo.User;
import com.pan.hisystem.pojo.UserInfo;
import com.pan.hisystem.service.IUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Description 个人中心
 * @Author qingyang
 * @Date 2022/4/6 22:53
 * @Version 1.0
 **/
@RestController
public class UserInfoController {

    @Autowired
    private IUserService userService;

    @ApiOperation(value = "更新用户信息")
    @PutMapping("/updateUser")
    public RespBean updateUser(@RequestBody User user){
        if(user==null){
            return RespBean.error("更新失败!");
        }
        if(userService.updateById(user)){
            return RespBean.success("更新成功!");
        }
        return RespBean.error("更新失败!");
    }

    @ApiOperation(value = "更新用户密码")
    @PutMapping("/updateUserPassword")
    public RespBean updateUserPassword(@RequestBody Map<String, Object> info) {
        String oldPass = (String) info.get("oldPass");
        String pass = (String) info.get("pass");
        Integer userId = (Integer) info.get("userId");
        return userService.updatePassword(oldPass, pass, userId);
    }

}
